# -*- coding: utf-8 -*-
from pargo.interfaces import IContent
from zope.dublincore.interfaces import IZopeDublinCore


def pretty_title_or_id(obj):
    """
    Return the best possible title or id of an item.
    """
    title = getattr(obj, 'title', None)
    if title: 
        return title
    
    if IContent.providedBy(obj):
        dc = IZopeDublinCore(obj)
        title = dc.Title()
    
    if title: 
        return title
    
    try:
        name = obj.getName()
    except AttributeError:
        name = repr(obj)
        
    return name
    
    